import java.util.*;

/**
 * @author LKQ
 * @date 2022/5/16 16:44
 * @description 模拟 建立虚拟节点模拟
 */
public class Solution {
    public static void main(String[] args) {

    }
    public ListNode partition(ListNode head, int x) {
        ListNode smaller = new ListNode(0);
        ListNode bigger = new ListNode(1);
        ListNode smallerHead = smaller;
        ListNode biggerHead = bigger;
        while (head != null) {
            if (head.val < x) {
                smaller.next = head;
                smaller = smaller.next;
            }else {
                bigger.next = head;
                bigger = bigger.next;
            }
            head = head.next;
        }
        // 最后的bigger.next需要置为空
        bigger.next = null;
        smaller.next = biggerHead.next;
        return smallerHead.next;
    }
}
